<template>
    <div class="wrap order">
        <div class="wrap-header">
            <div class="right mb8">
                <el-radio-group v-model="orderType" size="mini">
                    <el-radio-button label="1">我买进的</el-radio-button>
                    <el-radio-button label="0">我卖出的</el-radio-button>
                </el-radio-group>
            </div>
            <el-table
                :data="orderList"
                style="width: 100%">
                <el-table-column
                    prop="goodsName"
                    label="商品">
                </el-table-column>
                <el-table-column
                    prop="goodsCount"
                    width="100"
                    label="数量">
                </el-table-column>
                <el-table-column
                    prop="goodsSiglePrice"
                    width="100"
                    label="单价">
                </el-table-column>
                <el-table-column
                    prop="goodsTotalPrice"
                    width="100"
                    label="总价"></el-table-column>
                <el-table-column
                    v-if="orderType==='1'"
                    prop="sellInfo"
                    label="卖家信息"></el-table-column>
                <el-table-column
                    v-if="orderType==='1'"
                    fixed="right"
                    label="操作"
                    width="100">
                    <template slot-scope="scope">
                        <el-button @click="handleReceive(scope.row)" type="text" size="small" v-if="!scope.row.status">
                            确认收货
                        </el-button>
                        <el-button v-else type="text" size="small" disabled>已收货</el-button>
                    </template>
                </el-table-column>
            </el-table>

        </div>
    </div>
</template>

<script type="text/javascript">
    import _axios from "../../utils/axios";

    export default {
        name: "detail",
        data() {
            return {
                orderType: '1',
                orderList: [],
            }
        },
        methods: {
            handleReceive(item) {
                _axios.get('/api/api/goods/receiveGoods?orderId=' + item.id).then(res => {
                    if (res.code === 200) {
                        this.$message.success('操作成功');
                        this.getOrderList();
                    }
                })
            },
            getOrderList() {
                this.$api.mall.orderList({
                    "pageNum": 1,
                    "pageSize": 100,
                    "userId": sessionStorage.getItem('id'),
                    "type": this.orderType
                }).then(res => {
                    this.orderList = res.data.list;
                    this.orderList.forEach(item => {
                        item.sellInfo = item.sellerName + '+' + item.sellerMobile;
                    })
                })
            }
        },
        mounted() {
            this.getOrderList();
        },
        watch: {
            'orderType'(val) {
                this.getOrderList();
            }
        }
    }
</script>

<style rel="stylesheet/scss" lang="scss">
    .order {
        .right {
            float: right;
        }

    }
</style>
